﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Classes
    {
        private Model.ThesisDB db = new Model.ThesisDB();

        #region 对班级表查询数据功能的实现
        /// <summary>
        /// 获取班级表中所有班级名称
        /// </summary>
        /// <returns></returns>
        public string[] Search()
        {
            string[] classes = (from c in db.Class
                                   select c.Name).ToArray();
            return classes;
        }
        /// <summary>
        /// 获取班级表中指定院系名称对应的所有班级
        /// </summary>
        /// <param name="guid">院系名称对应的ID号</param>
        /// <returns></returns>
        public string[] Search(Guid guid)
        {
            string[] classes = (from c in db.Class
                                   where c.GradeID== guid
                                   select c.Name).ToArray();
            return classes;
        }
        /// <summary>
        /// 获取指定班级名称对应的ID号
        /// </summary>
        /// <param name="class">班级名称</param>
        /// <returns></returns>
        public Guid Search(string classes)
        {
            Guid guid = (from c in db.Class
                         where c.Name == classes
                         select c.ID).FirstOrDefault();
            return guid;
        }
        /// <summary>
        /// 获取指定班级名称对应的ID号
        /// </summary>
        /// <param name="class">班级名称</param>
        /// <returns></returns>
        public Guid Search(string classes,Guid gradeGuid)
        {
            Guid guid = (from c in db.Class
                         where c.Name == classes && c.GradeID == gradeGuid
                         select c.ID).FirstOrDefault();
            return guid;
        }
        #endregion

        #region 对班级表插入数据功能的实现
        /// <summary>
        /// 将班级信息数据写入到班级表中
        /// </summary>
        /// <param name="class"></param>
        public void Insert(Model.Class classes)
        {
            db.Class.InsertOnSubmit(classes);
            db.SubmitChanges();
        }
        #endregion

        #region 对班级表删除数据功能的实现
        /// <summary>
        ///删除指定的班级信息数据
        /// </summary>
        /// <param name="class"></param>
        public void Delete(string classes)
        {
            Model.Class cla = db.Class.Single(e => e.Name == classes);
            db.Class.DeleteOnSubmit(cla);
            db.SubmitChanges();
        }
        #endregion
    }
}
